package com.sunma.receive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sunma.common.annotation.Log;
import com.sunma.common.core.controller.BaseController;
import com.sunma.common.core.domain.AjaxResult;
import com.sunma.common.enums.BusinessType;
import com.sunma.receive.domain.AssetsReceive;
import com.sunma.receive.service.IAssetsReceiveService;
import com.sunma.common.utils.poi.ExcelUtil;
import com.sunma.common.core.page.TableDataInfo;

/**
 * 资产领用明细Controller
 * 
 * @author sunma
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/receive/receive")
public class AssetsReceiveController extends BaseController
{
    @Autowired
    private IAssetsReceiveService assetsReceiveService;

    /**
     * 查询资产领用明细列表
     */
    @PreAuthorize("@ss.hasPermi('receive:receive:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetsReceive assetsReceive)
    {
        startPage();
        List<AssetsReceive> list = assetsReceiveService.selectAssetsReceiveList(assetsReceive);
        return getDataTable(list);
    }

    /**
     * 导出资产领用明细列表
     */
    @PreAuthorize("@ss.hasPermi('receive:receive:export')")
    @Log(title = "资产领用明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetsReceive assetsReceive)
    {
        List<AssetsReceive> list = assetsReceiveService.selectAssetsReceiveList(assetsReceive);
        ExcelUtil<AssetsReceive> util = new ExcelUtil<AssetsReceive>(AssetsReceive.class);
        util.exportExcel(response, list, "资产领用明细数据");
    }

    /**
     * 获取资产领用明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('receive:receive:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetsReceiveService.selectAssetsReceiveById(id));
    }

    /**
     * 新增资产领用明细
     */
    @PreAuthorize("@ss.hasPermi('receive:receive:add')")
    @Log(title = "资产领用明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetsReceive assetsReceive)
    {
        return toAjax(assetsReceiveService.insertAssetsReceive(assetsReceive));
    }

    /**
     * 修改资产领用明细
     */
    @PreAuthorize("@ss.hasPermi('receive:receive:edit')")
    @Log(title = "资产领用明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetsReceive assetsReceive)
    {
        return toAjax(assetsReceiveService.updateAssetsReceive(assetsReceive));
    }
    /**
     * 修改资产数量
     */
    @PreAuthorize("@ss.hasPermi('receive:receive:edit')")
    @Log(title = "资产领用明细", businessType = BusinessType.UPDATE)
    @PutMapping("/editByReceiveOfReturnData")
    public AjaxResult editByReceiveOfReturnData(@RequestBody AssetsReceive assetsReceive)
    {
        return toAjax(assetsReceiveService.updateAssetsReceiveByReturnData(assetsReceive));
    }
    /**
     * 删除资产领用明细
     */
    @PreAuthorize("@ss.hasPermi('receive:receive:remove')")
    @Log(title = "资产领用明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetsReceiveService.deleteAssetsReceiveByIds(ids));
    }
}
